package com.mxf.example.utils.obs;

import com.qingstor.sdk.config.EnvContext;

import com.qingstor.sdk.service.QingStor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class QCloudObsTools {
    private final static Logger LOGGER = LoggerFactory.getLogger(QCloudObsTools.class);


    public static String zone;

    public static String accessKeyId;

    public static String secretAccessKey;

    private static QingStor qingStor = null;

    /**
     * @Description 获取对象
     * @Author mxf
     * @Date 2021/3/25 14:53
     * @Param
     * @Return
     * @Exception
     */

    private static QingStor getQingStor() {
        EnvContext evn = new EnvContext(accessKeyId, secretAccessKey);
        QingStor storService = new QingStor(evn, zone);
        LOGGER.info("QingStorSingleton,获取QingStor对象!");
        return storService;
    }


    /**
     * @Description 构建QingStor对象
     * @Author mxf
     * @Date 2021/3/25 14:53
     * @Param
     * @Return
     * @Exception
     */
    public static QingStor getQingStorSingleton() {
        if(null!=qingStor){
            return qingStor;
        }else {
            return getQingStor();
        }
    }

    @Value("${qingcloud.pek}")
    public  void setZone(String zone) {
        QCloudObsTools.zone = zone;
    }

    @Value("${qingcloud.access_key}")
    public  void setAccessKeyId(String accessKeyId) {
        QCloudObsTools.accessKeyId = accessKeyId;
    }

    @Value("${qingcloud.secret_key}")
    public  void setSecretAccessKey(String secretAccessKey) {
        QCloudObsTools.secretAccessKey = secretAccessKey;
    }
}
